package org.schoolnavigator.db;



import java.sql.Connection;
import java.sql.SQLException;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;

public class DBManager {
	private static DBManager dbManager = null;
	private DataSource ds = null;
	private Context ctx = null;
	
	private DBManager(){
		try{
			ctx = new InitialContext();
			ds = (DataSource)ctx.lookup("java:comp/env/jdbc/sc");
		}catch(NamingException ne){
			ne.printStackTrace();
		}
		
	}
	
	public static DBManager getInstance(){
		if(null == dbManager){
			dbManager = new DBManager();
		}
		return dbManager;
	}
	
	
	public Connection getConnection() throws SQLException{
		Connection con = null;
		
		try{
			con = ds.getConnection();
		}catch(SQLException sqle){
			sqle.printStackTrace();
		}
		return con;
	}

}
